<template>
	<view class="login">
		<view class="mpwx-login flex-col col-center row-center">
			<view class="avatar">
				<open-data type="userAvatarUrl"></open-data>
			</view>
			<view class="user-name mt20">
				<open-data type="userNickName"></open-data>
			</view>
			<view class="title xxl m-t-20 bold">微信授权绑定</view>
			<button size="lg" class="white br60 flex row-center btn" @click="getCodeUrl">
				<image class="m-r-10 image" src="/static/images/icon_wechat.png"></image>
				<text>微信一键授权</text>
			</button>
			<view class="muted m-t-20">微信授权后才可进行更多操作哦</view>
		</view>
	</view>
</template>

<script>
	import wechath5 from '@/utils/wechath5'
	
	export default{
		methods:{
			
			getCodeUrl() {
				wechath5.getWxUrls()
				// wechath5.getWxUrls().then(()=>this.bindingwx())
			},
			
			onLoad(option){
				console.log("页面重新加载")
				this.bindingwx(option)
			},
			
			async bindingwx(option) {
				// H5微信登录
				const {
					code
				} = this.$Route.query
				if (code) {
					// 带有code => 绑定
					wechath5.LoginBinding(code).then(res=>{
						 if(res.code == 1 ){
							 uni.navigateTo({
						  url:'/pages/index/index?type=666'
						})
						}else{
							this.$toast({
								title: res.message
							});
						}
						
					})
				}
			},
		}
	}
	
	
	
</script>

<style lang="scss">
	page{
		background-color: #fff;
		text-align: center;
		padding: 0;
		.login {
			min-height: 100vh;
			display: flex;
			flex-direction: column;
			.mpwx-login {
				min-height: 100vh;
				width: 100%;
				background-color: #FFFFFF;
				z-index: 998;
				flex: 1;
				position: absolute;
				.avatar {
					display: inline-block;
					width: 120rpx;
					height: 120rpx;
					border-radius: 50%;
					border: 1px solid #eee;
					overflow: hidden;
				}
				.user-name {
					height: 40rpx;
				}
			
				.image {
					width: 50rpx;
					height: 50rpx;
				}
			
				.btn {
					background-color: #09BB07;
					width: 580rpx;
					margin: 80rpx auto 0;
				}
			}
		}
	}
	
</style>
